package com.cr.mrapp.Controller;

import com.cr.mrapp.entity.Admin;
import com.cr.mrapp.entity.Item;
import com.cr.mrapp.service.AdminService;
import com.cr.mrapp.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
public class YydsController {

    //控制层依赖业务逻辑层

    @Autowired
    private AdminService adminService;

    @RequestMapping("/page/login")
    public String toLogin(){
        return "login";
    }

    @RequestMapping("/user/login.do")
    public String doLogin(String username, String password, HttpSession session){
        Admin admin = adminService.login(username,password);
        if (admin!=null){
            //把用户信息存入Session域
            session.setAttribute("user", admin);
            return "redirect:/page/index";
        }
        return "login";
    }

    @RequestMapping("/page/index")
    public String home(  ){
        return "index";
    }
}
